<template>
  <!-- 承运商管理 -->
  <div  >
    <div >
      <el-dialog title="设置承运商" class="tableDialog" :visible.sync="companyvisible" width="600px">
        <div class="headerMultiple">
          <section class="model-name">
            <span>{{truckNum}},共{{page.total}}个承运商</span>
          </section>
            <section>
                <div>
                    <el-button type="primary" size="small" @click="add" v-if="hasPermission('truck:truck:saveCompany')" >新增</el-button>
                </div>
            </section>
        </div>


        <!-- <section class="right-but" style="display:flex">
          <span style="margin-right:10px;cursor:pointer;" @click="getList(page)">
            <img style="width:44px;height:36px;margin-top:-15px" src="~@/assets/img/shuaxin.png">
          </span>
        </section> -->
        <el-table size="mini" v-loading="loading" :data="tableData" style="width: 100%; margin-top: 10px" border
          :header-cell-style="{
          'background-color': '#eeeeee !important',
        }" :row-class-name="tableRowClassName">
          <el-table-column type="index" label="序号" width="60" align="center">
            <template slot-scope="scope">
              <span>{{
              (page.pageNo - 1) * page.pageSize + scope.$index + 1
            }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="company.names" label="名称">
          </el-table-column>
          <el-table-column prop="address" label="操作" width="114px">
            <template slot-scope="scope">
              <el-link type="primary" :underline="false" v-if="hasPermission('company:company:del')" @click="delCrm(scope.row.id)">删除</el-link>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="page.pageSize"
          :current-page="page.pageNo" layout="total,prev, pager, next" :total="page.total">
        </el-pagination>
      </el-dialog>

    </div>

    <EditForm ref="EditForm" @refreshDataList="getList(page)"></EditForm>
    <ModifyForm ref="ModifyForm" @refreshDataList="getList(page)"></ModifyForm>
  </div>
</template>
<script>
  import {
    getList,
    delCrm,
    editState
  } from '@/api/market/crm.js'
  import EditForm from './editForm'
  import ModifyForm from './modifyForm'
  export default {
    components: {
      EditForm,
      ModifyForm
    },
    data () {
      return {
        companyvisible: false,
        ShowCloum: {
          createDate: ''
        },
        options: [{
            label: '上次操作时间',
            key: '2'
          },
          {
            label: '创建时间',
            key: 'createDate'
          }
        ],
        tableData: [{
          company: {},
          truck: {}
        }],
        orderBy: {
          name: 'update_date',
          method: 'desc'
        },
        loading: false,
        page: {
          pageSize: 10,
          pageNo: 1,
          total: 0
        },
        props: 3,
        truckId: '',
        truckNum: ''
      }
    },
    methods: {
      init (method, obj) {
        if (method === 'list') {
          this.companyvisible = true
          this.truckId = obj.id
          this.truckNum = obj.truckNumber
          this.props = 3
          this.getList(this.page, 3)
        }
      },
      // 获取列表带分页
      getList (params) {
        this.loading = true
        this.$http({
          url: '/truck/truck/companyList',
          method: 'get',
          params: {
            'pageNo': params.pageNo,
            'pageSize': params.pageSize,
            'truck.id': this.truckId
          }
        }).then((res) => {
          if (res.data.code === '200') {
            this.tableData = res.data.result.list
            this.page.total = res.data.result.count
          }
          this.loading = false
        })
      },
      // 删除客户
      delCrm (ids) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then((res) => {
          this.loading = true
          this.$http({
            url: '/truck/truck/deleteRelation',
            method: 'delete',
            params: {
              'ids': ids
            }
          }).then((res) => {
            if (res.data.code === '200') {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
              this.getList(this.page)
            }
          })
        })
      },
      // 添加
      add () {
        this.$refs.EditForm.init('add', this.truckId)
      },
      // 编辑
      edit (row) {
        let editForm = {}
        editForm.types = row.types
        editForm.id = row.id
        editForm.addressId = row.addressId
        editForm.names = row.names
        editForm.codes = row.codes
        editForm.idCard = row.idCard
        editForm.contactName = row.contactName
        editForm.contactPhone = row.contactPhone
        editForm.detailAddress = row.detailAddress
        editForm.countyCode = row.countyCode

        if (editForm.countyCode === 'undefined') {
          editForm.countyCode = ''
        }
        this.$refs.ModifyForm.init('edit', editForm)
      },
      handleSizeChange () {},
      handleCurrentChange (e) {
        this.page.pageNo = e
        this.getList(this.page)
      },
      tableRowClassName ({
        row,
        rowIndex
      }) {
        if (rowIndex % 2 === 1) {
          return 'warning-row'
        } else {
          return 'success-row'
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  ::v-deep .el-input--small .el-input__inner {
    height: 36px;
    line-height: 32px;
    width: 270px;
  }

  .queryForm {
    position: relative;

    .but-container {
      top: 10px;
      margin-left: 35px;
    }
  }

  .right-but {
    float: right;
    margin-right: 10px;
    margin-top: -20px;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }

  ::v-deep .el-table .warning-row {
    background: #f7f7f7;
  }
</style>
